SET(MANDATORY_LIBRARIES pagmo ${MANDATORY_LIBRARIES})
IF(PYTHON_VERSION_MAJOR LESS 3)
	SET(MANDATORY_LIBRARIES ${MANDATORY_LIBRARIES} ${Boost_PYTHON_LIBRARY})
ELSE(PYTHON_VERSION_MAJOR LESS 3)
	SET(MANDATORY_LIBRARIES ${MANDATORY_LIBRARIES} ${Boost_PYTHON3_LIBRARY})
ENDIF(PYTHON_VERSION_MAJOR LESS 3)

SET(PYGMO_INSTALL_PATH ${PYTHON_MODULES_DIR}/PyGMO)
ADD_DEFINITIONS(-DPAGMO_DLL_EXPORT_API -DPAGMO_BUILD_PYGMO)

IF(ENABLE_GTOP_DATABASE)
	ADD_DEFINITIONS(-DKEP_TOOL_DLL_EXPORT_API)
ENDIF(ENABLE_GTOP_DATABASE)

# Definitions needed when using the PaGMO DLL.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DYNAMIC_LIB_PAGMO_USE_FLAGS}")

# This MACRO accepts a module name (i.e. _problem) and creates the target library and install target
MACRO(PYTHON_CPPMODULE arg1)
	SET_TARGET_PROPERTIES(${arg1} PROPERTIES PREFIX "")
	IF(PYDEXTENSION)
		SET_TARGET_PROPERTIES(${arg1} PROPERTIES SUFFIX ".pyd")
	ELSEIF(SOEXTENSION)
		SET_TARGET_PROPERTIES(${arg1} PROPERTIES SUFFIX ".so")
	ENDIF(PYDEXTENSION)
	TARGET_LINK_LIBRARIES(${arg1} ${ARGN} ${MANDATORY_LIBRARIES} ${PYTHON_LIBRARY})
	STRING(REGEX REPLACE "^_" "" DIR_ARG ${arg1})
	INSTALL(TARGETS ${arg1}
		RUNTIME DESTINATION ${PYGMO_INSTALL_PATH}/${DIR_ARG}
		LIBRARY DESTINATION ${PYGMO_INSTALL_PATH}/${DIR_ARG}
	)
ENDMACRO(PYTHON_CPPMODULE)

# This MACRO is the same as above, but allows to set the install directory manually (useful when splitting the boost_python modules in more files)
MACRO(PYTHON_CPPMODULE_ADDITION arg1 arg2)
	SET_TARGET_PROPERTIES(${arg1} PROPERTIES PREFIX "")
	IF(PYDEXTENSION)
		SET_TARGET_PROPERTIES(${arg1} PROPERTIES SUFFIX ".pyd")
	ELSEIF(SOEXTENSION)
		SET_TARGET_PROPERTIES(${arg1} PROPERTIES SUFFIX ".so")
	ENDIF(PYDEXTENSION)
	TARGET_LINK_LIBRARIES(${arg1} ${ARGN} ${MANDATORY_LIBRARIES} ${PYTHON_LIBRARY})
	STRING(REGEX REPLACE "^_" "" DIR_ARG ${arg1})
	INSTALL(TARGETS ${arg1}
		RUNTIME DESTINATION ${PYGMO_INSTALL_PATH}/${arg2}
		LIBRARY DESTINATION ${PYGMO_INSTALL_PATH}/${arg2}
	)
ENDMACRO(PYTHON_CPPMODULE_ADDITION)

ADD_SUBDIRECTORY(algorithm)
ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(migration)
ADD_SUBDIRECTORY(problem)
ADD_SUBDIRECTORY(topology)
ADD_SUBDIRECTORY(test)
ADD_SUBDIRECTORY(util)

INSTALL(FILES __init__.py DESTINATION ${PYGMO_INSTALL_PATH})
